home *** CD-ROM | disk | FTP | other *** search
- Path: newsroom.hitc.com!kfreeman
- From: kfreeman@mandrake.HITC.COM (Keith Freeman)
- Newsgroups: comp.lang.c++,comp.os.linux.development.apps,comp.os.linux.misc
- Subject: Re: Are str* functions okay in C++?
- Date: 20 Mar 1996 17:24:32 GMT
- Organization: Hughes Team (EOSDIS)
- Message-ID: <KFREEMAN.96Mar20122432@mandrake.HITC.COM>
- References: <4hpvi0$gt6@news.platinum.com> <Do54G9.4Ly.0.server@indra.com>
- <Do61wK.IEG@beaver.cs.washington.edu> <3146A6B6.6455D253@indra.com>
- NNTP-Posting-Host: mandrake.hitc.com
- In-reply-to: Bear Giles's message of Wed, 13 Mar 1996 10:43:02 GMT
-
- In article <3146A6B6.6455D253@indra.com> Bear Giles <bear@indra.com> writes:
- >
- > Randy Chapman wrote:
- > > Bear Giles (bear@) wrote:
- > > : Also, another useful technique for this type of code is:
- > >
- > > : void procedure (argument...)
- > > : {
- > > : static char * buffer = 0;
- > >
- > > : if (buffer == 0)
- > > : buffer = malloc (2048); /* or any _large_ number */
- > > : ...
- > > However, it limits you to non-multithreaded programs. Its little things
- > > like this that make trying to use existing code in a multithreaded
- > > environment really hard sometimes =(
-
- And, this can cause very subtle problems in single-threaded programs.
- If your function returns a pointer to the buffer (like the standard
- library function strtok()), many users will naively:
-
- 1) call it several times, storing each returned (identical!)
- pointer somewhere;
-
- 2) place more than one call in the argument list passed to another
- function (all point to the same result, but which one?)
-
- keith freeman
- kfreeman@eos.hitc.com
-
-
-